package com.helper.dream.a361phonehelper.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.helper.dream.a361phonehelper.R;
import com.helper.dream.a361phonehelper.bean.TuijianBibeiEntity;

import java.text.ParsePosition;
import java.util.List;

import se.emilsjolander.stickylistheaders.StickyListHeadersAdapter;

/**
 * Created by LamYu on 16/12/22/0022.
 */

public class TuijianBibeiAdapter extends BaseAdapter implements StickyListHeadersAdapter {
    List<TuijianBibeiEntity.DataBean> data;
    LayoutInflater inflater;
    Context context;
    public TuijianBibeiAdapter(Context context,List<TuijianBibeiEntity.DataBean> data) {
        this.data = data;
        inflater=LayoutInflater.from(context);
        this.context=context;
    }

    @Override
    public View getHeaderView(int position, View convertView, ViewGroup parent) {
        HeadViewHolder holder=null;
        if (convertView==null){
            convertView=inflater.inflate(R.layout.item_tj_bb_tab,parent,false);
            holder=new HeadViewHolder(convertView);
            convertView.setTag(holder);
        }else{
            holder= (HeadViewHolder) convertView.getTag();
        }
        holder.tv.setText(data.get(position).getCategory_name());
        return convertView;
    }

    @Override
    public long getHeaderId(int position) {
        return data.get(position).getTag();
    }
    class HeadViewHolder{
        TextView tv;
        public HeadViewHolder(View view) {
            tv= (TextView) view.findViewById(R.id.tv_tj_bb_category);
        }
    }
//===========================================================
    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder=null;
        if (convertView==null){
            convertView=inflater.inflate(R.layout.item_tj_bb,parent,false);
            holder=new ViewHolder(convertView);
            convertView.setTag(holder);
        }else{
            holder= (ViewHolder) convertView.getTag();
        }
        Glide.with(context).load(data.get(position).getLogo_url()).into(holder.iv);
        holder.tvname.setText(data.get(position).getName());
        holder.tvnum.setText(data.get(position).getDownload_times());
        holder.tvword.setText(data.get(position).getSingle_word());
        return convertView;
    }
    class ViewHolder{
        ImageView iv;
        TextView tvname,tvnum,tvword;
        public ViewHolder(View view) {
            iv= (ImageView) view.findViewById(R.id.iv_tj_bb);
            tvname= (TextView) view.findViewById(R.id.tv_tj_bb_name);
            tvnum= (TextView) view.findViewById(R.id.tv_tj_bb_num);
            tvword= (TextView) view.findViewById(R.id.tv_tj_bb_word);
        }
    }
}
